package com.dc.refactoring._4_简化条件表达式._7_IntroduceNullObject;

import java.util.Optional;

public class Main {

    public static void main(String[] args){

        Outer outer = new Outer();

        // 原取值逻辑
        if (outer != null && outer.nested != null && outer.nested.inner != null) {
            System.out.println(outer.nested.inner.foo);
        }

        // -------------------------------------------------

        // 使用 Optional 替换后
        Optional.ofNullable(outer)
                .map(Outer::getNested)
                .map(Nested::getInner)
                .map(Inner::getFoo)
                .ifPresent(System.out::println);

    }


}
